


#include "Client_Connect.h"


Client_Connect::Client_Connect()
{
    
}

Client_Connect::Client_Connect(int a_nClient_socket_fd)
{
    this->client_socket_fd = a_nClient_socket_fd;
    server_addr = new sockaddr_in();
    httpUtil = new HTTP_Util<int>();
    //bzero(server_addr,sizeof(*server_addr));
    //server_addr->sin_addr.s_addr = inet_addr("127.0.0.1");
}

int Client_Connect::client_init()
{
    bzero(server_addr,sizeof(*server_addr));
    server_addr->sin_family=AF_INET;
    server_addr->sin_port=htons(80);
    server_addr->sin_addr.s_addr = inet_addr("192.168.1.200");
    server_addr_len = sizeof(*server_addr);
    
    return SERVER_DEFAULT_SUCCESS;
}


int Client_Connect::client_connect()
{
 
    int _connect_result = connect(client_socket_fd, (sockaddr*)server_addr,sizeof(sockaddr_in));//开始连接
    
    fprintf(stdout, "::: client fd: %d resule: %d", client_socket_fd, _connect_result);
    
    //send(client_socket_fd,"hello,this is client",strlen("hello,this is client")+1,0);
    
    return SERVER_DEFAULT_SUCCESS;
}


int Client_Connect::client_send()
{
        char buf[1024] = "";
        char _result[4096];
        HTTP_Package(_result, buf);
         
        int t_len = write(client_socket_fd, _result, strlen(_result));
        
        fprintf(stdout, "::: send length: %d", t_len);
        
        bzero(_result, 4096);
}


int Client_Connect::HTTP_Package(char* a_result, char* a_data)
{
    httpUtil->http_package(a_result, a_data);
    return SERVER_DEFAULT_SUCCESS;
}
